1. Field of the Invention
The invention relates to image processing. More specifically, the invention relates to the color space conversion.
2. Description of Related Art
Many digital video storage formats store pixel data in a color space known as YCrCb or YUV. In the YCrCb format, each pixel in an image is composed of three components, ‘Y’, ‘Cr’ and ‘Cb’. The ‘Y’ component contains luminance (intensity) information while the ‘Cr’ and ‘Cb’ components contain chrominance (color) information. The YCrCb format is most commonly found used in digital imaging devices such as DV (Digital Video) camcorders. Such devices produce images as an array of pixels each in YCrCb format. However, when interfacing such devices with computer display systems or other video rendering systems, a process known as color space conversion must be performed, since rendering in such systems often occurs with image pixels being in RGB (Red, Green and Blue) format. In RGB format, each pixel is represented as a combination of the three component colors Red, Green and Blue. This situation is illustrated in FIG. 1. Image information captured by a video capture device 110 is stored in YCrCb format and output to a computer system 120 as YCrCb data. In order for computer system 120 to render images to an output/display 130, it must send it RGB data. Hence, the computer system 120 is charged with the task of performing YCrCb to RGB color space conversion on images prior to rendering them on output/display 130.
Color space conversion of image information stored in YCrCb format to RGB format can be achieved by applying a conversion matrix to the components of the pixels. For instance, in one such conversion, a linear combination with specified coefficients for Y, Cr and Cb components of a pixel would yield a corresponding Red value for that pixel. Likewise, another linear combination, with another set of specified coefficients applied to the Y, Cr and Cb components for the same pixel would yield a Blue component value for that pixel. Yet another linear combination would yield the Green component. In a like manner, when converting from RGB back to YCrCb space, a three by three matrix can be applied to the R, G and B components of a given pixel to arrive at the Y, Cr and Cb components for the same pixel. Such conversions are repeatedly performed for all pixels of an image, and may be performed in any convenient order or manner.
If enough precision is used in storing values for color space components and also in the conversion computation, then a fairly problem-free result can be expected. However, in most real world applications and device environments, each component (or “channel”) is only accorded eight (8) bits when being stored with very little “headroom” (value ranges that can be used as precision overflows or underflows which do not represent meaningful image information). This fact leads to three common problems that occur due to color space conversion, namely “Chroma Clamping”, “Luma Clamping” and loss due to insufficient precision.
The range of values used for YCrCb data and for RGB data further exacerbates these problems. Y components range from +16 to +235. Cr/Cb components range from −112 to +112, offset by 128, for an effective range of +16 to +240. By contrast, R, G and B components all have ranges of 0 to +255. When computer system 120 receives YCrCb data from the video device 110, it is often in a compressed form. Such compression may include standards such as DV (Digital Video), Motion JPEG (Joint Photographic Expert Group), MPEG (Moving Picture Expert Group) and so on. Thus, it must be first be decompressed by the computer system 120. If converted to RGB space for the purpose of running image processing routines on the image data, then after the routines are run, the post-processed image data must often again be converted back into YCrCb space and then recompressed in order to be stored in the same format (such as DV etc.) in which it originated.
Chroma Clamping: Since color spaces are so different in nature, there may often be colors in eight-bit YCrCb that cannot be accurately described in RGB and vice versa. Those colors that fall outside the other color space's range will be clipped to the nearest value which is in range during the conversion. This can cause very saturated colors to become less saturated or intense. For instance, there are many YCrCb color values that map to RGB values greater than 255 or less than 0. For example, a highly saturated color having Y=155, Cb=174 and Cr=220, would probably be mapped (if typical conversion matrices were used) to RGB values of R=255, G=69 and B=255. When mapping back into YCrCb, the result would be Y=141, Cb=182 and Cr=196, which is a shift of color and reduction in brightness from the original. This is the Chroma Clamping phenomenon.
Luma Clamping: Many YCrCb to RGB conversion routines are configured to the maximum range in the target space based upon allowed values in the source space. YCrCb defines for video use a range of 16-235 for Y which is then mapped to a range of 0-255 in the RGB space, giving maximum dynamic range. Unfortunately however, many digital video devices produce Y values far above the restricted range, even as high as Y=254. When such values are converted to RGB, they cannot exceed 255, and so are clamped there. When the RGB is converted back to YCrCb, the Y value will attain its maximum of 235, but this is still much lower than the original value of 254. This causes a difference in what is viewed, particularly in that the luminosity is not fully available. This is the Luma Clamping Phenomenon.
While some color space conversion routines that do map the full range of Y into the full range of RGB do not suffer Luma Clamping, as discussed below, they may suffer even more loss due to precision errors. These losses are greater because the YCrCb values outside the industry-standard recommended ranges have to still be mapped into the industry-standard recommended range for RGB, as are those mapped by all other routines.
Precision Loss: When performing a color space conversion from YCrCb to RGB, three linear combination of the three 8-bit YCrCb components yields the three R, G, and B converted components. When converting these back to YCrCb yet another set of three linear combinations is applied to achieve the recovered YCrCb components. The inverse linear combinations do not necessarily map the converted R, G and B values back to the original Y, Cr, and Cb values due to the eight bit limitation and due to inherent lack of inverse symmetry in the linear combinations. In other words, YcrCb-->RGB-->Y′Cr′Cb′, where Y, Cr and Cb, do not necessarily equal Y′, Cr′ and Cb′, respectively.
There is needed a method and apparatus for adjusting color values during color space conversion so that Luma Clamping, Chroma Clamping and loss due to precision can be avoided.